<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="HSDSummary_div" style="width: 100%;height: 100%;text-align: center">
        <div id="HSDSummary_div_form">
            <h1>收发存汇总表</h1>
            <form id="HSDSummary_form">
                <div  style="margin-top: 20px">
                    <!-- 组织-->
                    <input id="HSDSummary_combobox_org" class="easyui-combobox" name="pkOrg"
                           data-options="label:'组织',labelWidth:'40',valueField:'pkOrg',textField:'name',url:'/HSDSummary/getOrg',width:230">

                    <!-- 仓库 -->
                    <select  id="HSDSummary_combotree" name="warehouseCode" class="easyui-combotree" style="width:230px;" data-options="disabled:'true',prompt:'请先选择组织',label:'仓库',labelWidth:'40'"></select>
                </div>
                <div id="HSDSummary_div_datebox" style="margin-top: 20px">
                    <input  id="HSDSummary_datebox_start" name="startDate" type="text" class= "easyui-datebox" required ="required" data-options="prompt:'开始时间',label:'时间',labelWidth:'40',width:150">-
                    <input  id="HSDSummary_datebox_end" name="endDate" type= "text" class= "easyui-datebox" required ="required" data-options="prompt:'结束时间',width:110">
                    <span style="display: none">
                        <input id="HSDSummary_datebox_uuid" name="uid" class= "easyui-textbox" >
                    </span>
                    <input  id="HSDSummary_combobox_way" name="way" type= "text" style="width:190px;" class= "easyui-combobox" required ="required" data-options="labelAlign:'right',label:'汇总方式',labelWidth:'60',
                        valueField: 'wayValue',textField: 'wayName',
                        data: [{
                            wayName: '仓库+品号',
                            wayValue: '1'
                        },{
                            wayName: '仓库+品号+批次',
                            wayValue: '2'
                        }]">
                </div>
                <div style="margin-top: 20px">
                    <a id="HSDSummaryEmptyBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'">清理缓存</a>
                    <a id="HSDSummary_btn1" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',disabled:true">生成数据</a>
                    <a id="HSDSummary_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',disabled:true">查看</a>
                </div>
            </form>
        </div>
        <div  id="HSDSummary_div_datagrid">
            <table id="HSDSummary_datagrid" style="height:100%"></table>
        </div>
    </div>
    <script th:inline="none" type="text/javascript">

        $("#HSDSummary_combobox_org").combobox({
        onChange:function (newValue, oldValue) {
            var hsdSummaryCombotree=$("#HSDSummary_combotree");
            //触发事件：打开选择仓库
            hsdSummaryCombotree.combotree({
                url: '/HSDSummary/getStordoc?pkOrg='+newValue,
                required: true,
                disabled:false,
                multiple:true,
                editable:true,
                //触发事件：显示时间
                onChange:function (newValue, oldValue){
                    if (newValue==""){
                        //$("#HSDSummary_div_datebox").hide();
                        //清空日期
                       // $("#HSDSummary_datebox_start").datebox("setValue","");
                       // $("#HSDSummary_datebox_end").datebox("setValue","");
                    }else{
                        //$("#HSDSummary_div_datebox").show();
                    }
                }
            })
        }
    })

    //清空数据
    $("#HSDSummaryEmptyBtn").linkbutton({
        onClick:function() {
           var msg=commonAjax("get","/HSDSummary/emptyDate");
           if (msg.status==200){
               $("#HSDSummary_btn1").linkbutton("enable") //启用
               $("#HSDSummaryEmptyBtn").linkbutton("disable")//禁用按钮
               $("#HSDSummary_datagrid").datagrid('loadData',[]);//此语句第一次操作会报错(因为还没有初始化表格)，没提示更好了
               layer.msg(msg.msg)
           }else {
               layer.msg(msg.msg)
           }
        }
    })
    //生成数据
    $("#HSDSummary_btn1").linkbutton({
        onClick:function() {
            $("#HSDSummary_btn1").linkbutton("disable")//禁用按钮
            HSDSummaryCreate();
        }
    })

    //点击查询时间获取数据
    $("#HSDSummary_btn").linkbutton({
        onClick:function() {
           // $("#HSDSummary_btn").linkbutton("disable")//禁用按钮
            initHSDSummaryDatagrid()

        }
    })

    //分页工具
    $("#HSDSummary_datagrid_pagination").pagination({
        onSelectPage:function(pageNumber, pageSize){ //事件方法
           // $("#HSDSummary_datagrid_pagination").pagination("disable")
           // $(this).pagination('loading');
            HSDSummarySubmit(pageNumber, pageSize);
           // $(this).pagination('loaded');
        }

    })

        //生成数据方法
    function HSDSummaryCreate(){

        $("#HSDSummary_form").form('submit', {
            url:"/HSDSummary/createData",
            onSubmit: function(){
                //赋值uuid
                $("#HSDSummary_datebox_uuid").textbox("setValue",guid())
                var isValid = $(this).form('validate');
                if(!isValid){
                    $("#HSDSummary_btn1").linkbutton("enable")//启用按钮
                }else {
                    //打开进度条：条提示窗口
                    $.messager.progress({msg:"正在生成数据，结束后请点击【查看】按钮",interval:600});
                }
                return isValid;	// 返回false终止表单提交
            },
            success:function(data){
                var data = eval('(' + data + ')');
                if (data.statu==200){
                    $("#HSDSummary_btn").linkbutton("enable")//启用按钮
                    $("#HSDSummaryEmptyBtn").linkbutton("enable")//启用'清空数据'按钮
                }
                //关闭进度条：提示窗口
                $.messager.progress('close');
                windowsOperation(null,null,data);
            }

        });
    }

    //初始化表格
    function initHSDSummaryDatagrid() {
        $("#HSDSummary_datagrid").datagrid({
                pagination:true,
                url:"/HSDSummary/queryData",
                nowrap: false,
                autoRowHeight: false,
                pageList:[20,50,100,200,500],
                pageSize:500,
                columns: [[
                    {field: 'pkOrg', title: '组织', width: 80, align: 'center'},
                    {field: 'stocno', title: '仓库编码', width: 40, align: 'center'},
                    {field: 'stocnm', title: '仓库', width: 100, align: 'center'},
                    {field: 'itemno', title: '材料编码', width: 100, align: 'center'},
                    {field: 'itemnm', title: '材料名称', width: 150, align: 'center'},
                    {field: 'materialspec', title: '材料规格', width: 100, align: 'center'},
                    {field: 'materialtype', title: '型号', width: 100, align: 'center'},
                    {field: 'materialcategories', title: '材料类型', width: 80, align: 'center'},
                    {field: 'vbatchcode', title: '批次', width: 100, align: 'center'},
                    {field: 'huoweihao', title: '货位号', width: 50, align: 'center'},
                    {field: 'racknm', title: '货位', width: 50, align: 'center'},
                    {field: 'unitnm', title: '单位', width: 40, align: 'center'},
                    {field: 'unitweight', title: '单位克重', width: 80, align: 'center'},
                    {field: 'customsno', title: '归并号', width: 60, align: 'center'},
                    {field: 'customsnm', title: '归并号名称', width: 80, align: 'center'},
                    {field: 'initqty', title: '期初数量', width: 60, align: 'center'},
                    {field: 'initMoney', title: '期初金额', width: 100, align: 'center'},
                    {field: 'inQty', title: '入库数量', width: 30, align: 'center'},
                    {field: 'inMoney', title: '入库金额', width: 30, align: 'center'},
                    {field: 'outQty', title: '出库数量', width: 30, align: 'center'},
                    {field: 'outMoney', title: '出库金额', width: 30, align: 'center'},
                    {field: 'endQty', title: '结存数量', width: 100, align: 'center'},
                    {field: 'endMoney', title: '结存金额', width: 100, align: 'center'},
                    {field: 'price', title: '结存单价', width: 100, align: 'center'}
                ]],
            toolbar: [
                {
                text: '导出当前页面数据',
                iconCls: 'icon-export-excel',
                handler: function () {
                    var start = $("#HSDSummary_datebox_start").datebox("getValue");
                    var end = $("#HSDSummary_datebox_end").datebox("getValue");

                    $('#HSDSummary_datagrid').datagrid('toExcel', '收发存汇总表(' + start + '~' + end + ').xls');
                    // $('#HSDSummary_datagrid').datagrid('toExcel', {
                    //     filename: 'datagrid.xls',
                    //     worksheet: 'Worksheet'
                    // });
                }
            },'-',
                {
                text:'导出全部数据',
                iconCls: 'icon-export-excel',
                handler: function() {
                    var start = $("#HSDSummary_datebox_start").datebox("getValue");
                    var end = $("#HSDSummary_datebox_end").datebox("getValue");
                    window.location.href="/HSDSummary/exportData?startDate="+start+"&endDate="+end
                    // $.ajax({
                    //     url:"/HSDSummary/exportData",
                    //     data:{"startDate":start,"endDate":end},
                    //     async:false,
                    //     success:function (data) {
                    //         console.log("共数据："+data)
                    //     }
                    // })

                }

            }]

        })
    }
    function guid() {
        return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0,
                v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }
    //初始化页面高度，设置datagrid高度
    var hsdSummarytotalHeight=document.getElementById("HSDSummary_div").offsetHeight;//获取总高度
    var hsdSummaryFormHeight=document.getElementById("HSDSummary_div_form").offsetHeight;
    //console.log("总高度：",hsdSummarytotalHeight)
    //console.log("表单的高度：",hsdSummaryFormHeight)
    $("#HSDSummary_div_datagrid").css({"height":hsdSummarytotalHeight-hsdSummaryFormHeight-60+"px"});
</script>
</body>
</html>